package com.cskaoyan.controller.stage;

import com.cskaoyan.exception.UnLoginException;
import com.cskaoyan.model.vo.BaseRespVO;
import com.cskaoyan.model.vo.ExceptionVO;
import com.cskaoyan.model.vo.WXUserVO;
import com.cskaoyan.service.WxUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：王李轶群
 * @description：用户界面
 * @date ：5/7/22 3:49 PM
 */
@RestController
@RequestMapping("wx/user")
public class WxUserController {
    @Autowired
    WxUserService wxUserService;

    @RequestMapping("index")
    public ExceptionVO userIndex(){
        Subject subject = SecurityUtils.getSubject();
        if (!subject.isAuthenticated()) {
            return ExceptionVO.error(501, "请先登录");
        }
        String username = (String) subject.getPrincipals().getPrimaryPrincipal();
        // try{
        //     Subject subject = SecurityUtils.getSubject();
        //     username = (String) subject.getPrincipals().getPrimaryPrincipal();
        // }catch (NullPointerException ex){
        //     BaseRespVO<WXUserVO> wxUserVOBaseRespVO = new BaseRespVO<>();
        //     return wxUserVOBaseRespVO;
        // }
        BaseRespVO<WXUserVO> userIndex = wxUserService.getUserIndex(username);

        return userIndex;
    }

}
